package kwic;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class ReadFilter extends Filter
{
  public void putData(Object o)
  {
    String s = (String) o;
    File file = new File(s);
    
    if (file.exists() && file.isFile())
    {
      try
      {
        RandomAccessFile r = new RandomAccessFile(s, "r");
        String line;
        while ((line = r.readLine()) != null)
        {
          Line l = new Line();
          for (String str : line.split(" "))
            l.add(new Word(str));
          super.putData(l);
        }
        super.putData(null);
      }
      catch (IOException io)
      {
        System.out.println("Fout bij het lezen van de file '" + s + "'");
        System.exit(1);
      }
    }
    else
    {
      System.out.println("File '" + s + "' niet gevonden");
      System.exit(1);
    }
  }

}
